{% extends 'base.html' %}
{% block title %}{% endblock %}
{% load staticfiles %}
{% block custom_bread %}
    <section>
        <div class="wp">
            <ul class="crumbs">
                <li><a href="/">首页</a>></li>
                <li><a href="{% url 'teacher:teacher_list' %}">教练</a>></li>
                <li>教练详情</li>
            </ul>
        </div>
    </section>
{% endblock %}
{% block content %}
    <section>
        <div class="wp butler-detail-box butler-diaryd-box clearfix">
            <div class="fl list">
                <div class="butler_detail_list clearfix">
                    <div class="brief">
                        <dl class="des">
                            <dt>
                                <div class="picpic">
                                    <img width="100" height="100" src="{{ MEDIA_URL }}{{ teacher.user.image }}"/>
                                </div>
                                <div class="btn">
                                <span class="fl btn1 collectionbtn" id="jsLeftBtn" style="margin-left: 38px">
                                     {% if has_teacher_faved %}已收藏{% else %}收藏{% endif %}
                                </span>

                                    <a href="#" class="bds_more" data-cmd="more"></a>

                                </div>
                            </dt>
                            <dd>
                                <a href="">
                                    <h1>{{ teacher.user.username }}<span class="key picbig">金牌教练</span></h1>
                                </a>
                                <ul class="cont">
                                    <li>性别：<span>{{ teacher.user.get_sex_display }}</span></li>
                                    <li>地址：<span>{{ teacher.user.address }}</span></li>
                                </ul>
                            </dd>
                        </dl>
                    </div>
                </div>
                <div class="butler_detail_cont clearfix">
                    <div class="left layout">
                        <div class="head">
                            <ul class="tab_header">
                                <li class="active">教授课程</li>
                            </ul>
                        </div>
                        <div class="companycenter">
                            <div class="group_list brief">
                                {% for teacher_course in all_courses %}
                                    <div class="module1_5 box">
                                        <a href="{% url 'course:course_detail' teacher_course.id %}">
                                            <img width="214" height="190"
                                                 src="{{ MEDIA_URL }}{{ teacher_course.image }}"/>
                                        </a>
                                        <div class="des">
                                            <a href="{% url 'course:course_detail' teacher_course.id %}">
                                                <h2>{{ teacher_course.name }}</h2></a>
                                            <span class="fl">时长：<i
                                                    class="key">{{ teacher_course.learn_times }}</i></span>
                                            <span class="fr">订阅人数：{{ teacher_course.fav_nums }}</span>
                                        </div>

                                    </div>
                                {% endfor %}

                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        </div>
    </section>
{% endblock %}


{% block custom_js %}
    <script type="text/javascript">


        //收藏分享
        function add_fav(current_elem, fav_id, fav_type) {
            $.ajax({
                cache: false,
                type: "POST",
                url: "{% url "teacher:addfav" %}",
                data: {'fav_id': fav_id, 'fav_type': fav_type},
                async: true,
                beforeSend: function (xhr, settings) {
                    xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                },
                success: function (data) {
                    if (data.status == 'fail') {
                        if (data.msg == '用户未登录') {
                            window.location.href = "/login/";
                        } else {
                            alert(data.msg)
                        }

                    } else if (data.status == 'success') {
                        current_elem.text(data.msg)
                    }
                },
            });
        }

        $('#jsLeftBtn').on('click', function () {
            add_fav($(this), {{ teacher.user.id }}, 3);
        });



    </script>

{% endblock %}

